//
//  DYMySettingsViewController.m
//  DaYing
//
//  Created by DaYing  on 2023.
//  Copyright © 2023 DaYing . All rights reserved.
//

#import "DYMySettingsViewController.h"

#import "DYTrySubscribeCell.h"
#import "DYCurrencySelectCell.h"

@interface DYMySettingsViewController ()

@end

@implementation DYMySettingsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setNavigationItemTitleViewWithTitle:@"我的"];

    [self.tableView registerNib:[UINib nibWithNibName:@"DYTrySubscribeCell" bundle:nil] forCellReuseIdentifier:@"DYTrySubscribeCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"DYCurrencySelectCell" bundle:nil] forCellReuseIdentifier:@"DYCurrencySelectCell"];
    
    self.tableView.frame = CGRectMake(0,self.navigationBarHeight, kScreenWidth, kScreenHeight - self.navigationBarHeight);
    [self.view bringSubviewToFront:self.navigationBar];
}

//成功刷新界面
- (void)subscriptionSuccessfullyRefreshed {
    [self refreshData];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self refreshData];
}

- (void)complete {
    [self refreshData];
}

#pragma mark - cellDataSource

- (NSArray *)cellDataSource {
    
    if (!self.dataSource) {
        NSMutableArray *arr = [NSMutableArray arrayWithCapacity:4];
        
        __block NSMutableArray *subarr = nil;
        __block NSDictionary *dict = nil;
        
//        subarr = [NSMutableArray arrayWithCapacity:1];
//
//        dict =  @{@"class":DYTrySubscribeCell.class,
//                  @"height":@([DYTrySubscribeCell getCellFrame:[NSNumber numberWithFloat:(kScreenWidth - 14*2)*152/347 + 50]]),
//                  @"delegate":@YES};
//        [subarr addObject:dict];
//
//        [arr addObject:subarr];
        
        [self.dataAry enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger idx, BOOL * _Nonnull stop) {
            //第二段
            subarr = [NSMutableArray arrayWithCapacity:1];
            
            //服务条款
            dict =  @{@"class":DYCurrencySelectCell.class,
                      @"height":@([DYCurrencySelectCell getCellFrame:[NSNumber numberWithFloat:(kScreenWidth - 15*2)*120/345/2]]),
                      @"data":[DYCurrencySelectCellModel ittemModelWithDic:dic],
                      @"delegate":@YES};
            [subarr addObject:dict];
            
            [arr addObject:subarr];
        }];

        self.dataSource = arr;
    }
    return self.dataSource;
}

- (NSArray *)dataAry {
    NSArray *ary = @[
        @{@"ico":@"fwtk",
        @"title":@"服务条款"},

        @{@"ico":@"yszc",
        @"title":@"隐私政策"}
    ];
    return ary;
}

#pragma mark DYTrySubscribeCellDelegate

- (void)trySubscribeCell:(DYTrySubscribeCell *)cell button:(UIButton *)sender {
    if (!kUserManager.userManager.isSubscribe) {
        [self gotoSubscribeViewController];
    }
}

#pragma mark - QBCurrencySelectCellDelegate 服务条款 隐私政策

- (void)currencySelectCell:(DYCurrencySelectCell *)cell button:(UIButton *)sender {
    [self gotoBaseWebViewController:cell.titleLabel.text url:@""];
}

@end

